import openpyxl


class ExcelUtil:
    @staticmethod
    def read(filename, sheet_name, min_row, max_row, min_colum, max_colum):
        workbook = openpyxl.load_workbook(filename, read_only=True)
        sheet = workbook[sheet_name]
        data = [[sheet.cell(row=i, column=j).value for j in range(min_colum, max_colum + 1)]
                for i in range(min_row, max_row + 1)]
        workbook.close()
        return data

    @staticmethod
    def demo(filename, sheet_name):
        workbook = openpyxl.Workbook()
        workbook.create_sheet(title=sheet_name)
        sheet = workbook[sheet_name]
        for i in range(1, 10):
            for j in range(1, i + 1):
                sheet.cell(row=i, column=j, value=f"{j} * {i} = {i * j}")
        workbook.save(filename)
        workbook.close()


if __name__ == '__main__':
    print(ExcelUtil().read('../Web_auto/datas.xlsx', 'login', 2, 4, 1, 5))
